<?php
/*
$JA#COPYRIGHT$
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

class modJAJobsMap{
	function get_list_jobs( $model, $mode='', $fieldlist, $params ){
		global $jbconfig, $mainframe;
		$arrReturn  = array();
				
		$data 			= "";
		$db = JFactory::getDBO ();
		$locations = $params->get("job_areas", "0");
		
		if( is_array($locations) ){		    
		    $locations = "('".implode("','", $locations)."')";
		}else $locations = "('".$locations."')";
		
		$where_more = " and a.status='Approved' AND a.location_id IN {$locations} ";
		$where_more .= ' and(a.effected_date<=now()) and ( (DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_display_days', 30). ' DAY) >= now()  AND a.is_hotjob=0) or (DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_show_days_elapsed', 30). ' DAY) >= now() ) )';
		$all_items = $model->getItems($where_more, '', 0, '', true);
		
		return $all_items;
	}
		
	function _findItem()
	{
		$needles = array(
			'view' 		=> 'jajobs',
			'layout'  	=> 'jalist'
		);
		$component =& JComponentHelper::getComponent('com_jajobboard');

		$menus	= &JApplication::getMenu('site', array());
		$items	= $menus->getItems('componentid', $component->id);

		$match 	= null;
		
		if (is_array($items))
		foreach($items as $item)
		{
			if ((@$item->query['view'] == 'jajobs') && (@$item->query['layout'] == 'jalist')) {
				$match = $item;
				break;
			}
		}
		
		if($match)	return $match->id;
		return null;
	}
}